package com.yaohe.consumer.network.msghandler.impl;

import java.util.List;

import org.apache.mina.core.session.IoSession;

import android.util.Log;

import com.yaohe.common.Coupon;
import com.yaohe.consumer.network.msghandler.MessageHandler;
import com.yaohe.consumer.service.YaoheService;
import com.yaohe.protocols.ProtocolFactory;
import com.yaohe.protocols.ProtocolProtos.Protocol;
import com.yaohe.protocols.ProtocolProtos.Protocol.CouponList;
import com.yaohe.protocols.ProtocolProtos.Protocol.IdList;


public class InfoFetchHandler implements MessageHandler{

	private static InfoFetchHandler infoFetchHandler = new InfoFetchHandler();
	
	public static InfoFetchHandler getHandler(){
		return infoFetchHandler;
	}
	

	public void handle(Protocol message, IoSession session) {
		// TODO Auto-generated method stub

		List<Coupon> recCouponList;
		try {
			Log.d("YaoheService","Come to InfoFetchHandler!");
			recCouponList = ProtocolFactory.decodeCouponList(message.getMessage().getCouponFetchResponse().getCouponList());
			YaoheService.dealWithInfoFetch(recCouponList);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			Log.d("YaoheService","Error at InfoFetchHandler:" + e.getMessage());
		}
	}

}
